package com.ruibang.glass.material.service.impl.bcp;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.material.domain.req.bcp.MaterialBCPInventoryReq;
import com.ruibang.glass.material.entity.bcp.MaterialBCPInventoryManagement;
import com.ruibang.glass.material.mapper.bcp.GMaterialBcpInventoryManagementMapper;
import com.ruibang.glass.material.service.bcp.GMaterialBCPInventoryManagementService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 原材料库存管理表 服务实现类
 * </p>
 *
 * @author mameng
 * @since 2024-04-01
 */
@Service
public class GMaterialBCPInventoryManagementServiceImpl extends ServiceImpl<GMaterialBcpInventoryManagementMapper, MaterialBCPInventoryManagement> implements GMaterialBCPInventoryManagementService {

    @Override
    public IPage<MaterialBCPInventoryManagement> getPage(MaterialBCPInventoryReq materialInventoryReq) {
        LambdaQueryWrapper<MaterialBCPInventoryManagement> queryWrapper = Wrappers.<MaterialBCPInventoryManagement>lambdaQuery();
        if (StringUtils.isNotBlank(materialInventoryReq.getMaterialCode())) {
            queryWrapper.like(MaterialBCPInventoryManagement::getMaterialCode, materialInventoryReq.getMaterialCode());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getBatchNumber())) {
            queryWrapper.like(MaterialBCPInventoryManagement::getBatchNumber, materialInventoryReq.getBatchNumber());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getStorageLocation())) {
            queryWrapper.like(MaterialBCPInventoryManagement::getStorageLocation, materialInventoryReq.getStorageLocation());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getLevelFinish())) {
            queryWrapper.eq(MaterialBCPInventoryManagement::getLevelFinish, materialInventoryReq.getLevelFinish());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getSpecification())) {
            queryWrapper.eq(MaterialBCPInventoryManagement::getSpecification, materialInventoryReq.getSpecification());
        }

        Page<MaterialBCPInventoryManagement> materialWarehouseInfoPage = baseMapper.selectPage(new Page<>(materialInventoryReq.getPageNo(), materialInventoryReq.getPageSize()),
                queryWrapper.orderByDesc(MaterialBCPInventoryManagement::getCreateTime)
        );
        return materialWarehouseInfoPage;

    }
}
